#include "../include/head.h"

void LogQueue::push(const std::string& msg) {
    std::lock_guard<std::mutex> lock(mutex_);
    queue_.push(msg);
    cond_var_.notify_one();
}

bool LogQueue::pop(std::string& msg) {
    std::unique_lock<std::mutex> lock(mutex_);
    while (queue_.empty() && !is_shutdown_) {
        cond_var_.wait(lock);
    }
    if (is_shutdown_ && queue_.empty()) {
        return false;
    }
    msg = queue_.front();
    queue_.pop();
    return true;
}

void LogQueue::shutdown() {
    std::lock_guard<std::mutex> lock(mutex_);
    is_shutdown_ = true;
    cond_var_.notify_all();
}